import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:niuniu/common/constant/AppColor.dart';
import 'package:niuniu/common/constant/AppRadius.dart';
import 'package:niuniu/pages/my/dark_pattern/controller.dart';
import 'package:get/get.dart';

class DarkPatternPage extends GetView<DarkPatternController> {
  const DarkPatternPage({Key? key}) : super(key: key);

  // 主视图
  Widget buildView() {
    return Column(
      children: [
        Container(
          alignment: Alignment.center,
          padding: EdgeInsets.only(left: 10.w, right: 10.w),
          height: 70.h,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(AppRadius.card),
            color: AppColor.cardBgColor,
          ),
          child: ListTile(
            contentPadding: EdgeInsets.zero,
            title:  Text("跟随系统", style: TextStyle(color: AppColor.firstFontColor)),
            subtitle:  Text("开启后，将跟随系统打开或关闭深色模式", style: TextStyle(color: AppColor.firstFontColor)),
            trailing: CupertinoSwitch(
                activeColor: Colors.greenAccent,
                thumbColor: Colors.white,
                trackColor: Colors.black26,
                value: false,
                onChanged: (value) => {}),
          ),
        ),
        SizedBox(height: 15.h),
        Align(alignment: Alignment.centerLeft, child: Text("手动选择", style: TextStyle(color: AppColor.firstFontColor))),
        SizedBox(height: 5.h),
        Container(
          padding: EdgeInsets.only(left: 10.w, right: 10.w),
          height: 120.h,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(AppRadius.card),
            color: AppColor.cardBgColor,
          ),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              ListTile(
                  contentPadding: EdgeInsets.zero,
                  title: Text("白天模式", style: TextStyle(color: AppColor.firstFontColor)),
                  trailing: Icon(Icons.check,
                      color: Get.isDarkMode
                          ? Colors.transparent
                          : AppColor.themeColor),
                  onTap: () {
                    Get.changeTheme(ThemeData.light());
                  }),
              ListTile(
                  contentPadding: EdgeInsets.zero,
                  title: Text("黑夜模式", style: TextStyle(color: AppColor.firstFontColor)),
                  trailing: Icon(Icons.check,
                      color: Get.isDarkMode
                          ? AppColor.themeColor
                          : Colors.transparent),
                  onTap: () {
                    Get.changeTheme(ThemeData.dark());
                  }),
            ],
          ),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<DarkPatternController>(
      init: DarkPatternController(),
      id: "dark-pattern-page",
      builder: (_) {
        return Scaffold(
            appBar: AppBar(title: const Text("深色模式")),
            body: SafeArea(
              child: Container(
                margin: EdgeInsets.only(left: 15.w, right: 15.w),
                child: buildView(),
              ),
            ));
      },
    );
  }
}
